mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 18:42:30 +03:00
8c41ff539a
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2581 Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com> GitOrigin-RevId: 327c26868102ea1c277b795b9f508847faa2ae8b
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package projectmetadata
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/hasura"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/version"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2"
|
|
)
|
|
|
|
func TestPrintContextRichDiffBetweenProjectDirectories(t *testing.T) {
|
|
type args struct {
|
|
opts PrintContextRichDiffBetweenProjectDirectoriesOpts
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
out *bytes.Buffer
|
|
wantErr bool
|
|
}{
|
|
{
|
|
"t1",
|
|
args{
|
|
opts: func() PrintContextRichDiffBetweenProjectDirectoriesOpts {
|
|
ec := cli.NewExecutionContext()
|
|
ec.Logger = logrus.New()
|
|
ec.Version = version.New()
|
|
ec.Config = &cli.Config{Version: cli.V3}
|
|
ec.HasMetadataV3 = true
|
|
ec.APIClient = &hasura.Client{}
|
|
ec.Version.ServerFeatureFlags = &version.ServerFeatureFlags{
|
|
HasAccessKey: false,
|
|
HasAction: true,
|
|
HasCronTriggers: true,
|
|
}
|
|
p := PrintContextRichDiffBetweenProjectDirectoriesOpts{
|
|
EC: ec,
|
|
MetadataHandler: NewHandlerFromEC(ec),
|
|
FromDirectory: "testdata/diff/t1/server/metadata",
|
|
ToDirectory: "testdata/diff/t1/project/metadata",
|
|
DisableColor: false,
|
|
}
|
|
return p
|
|
}(),
|
|
},
|
|
new(bytes.Buffer),
|
|
false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
tt.args.opts.Writer = tt.out
|
|
err := PrintContextRichDiffBetweenProjectDirectories(tt.args.opts)
|
|
if tt.wantErr {
|
|
assert.Error(t, err)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
goldenFile := filepath.Join("testdata/diff", tt.name, "want")
|
|
// uncomment to update test snapshot file
|
|
//assert.NoError(t, ioutil.WriteFile(goldenFile, tt.out.Bytes(), os.ModePerm))
|
|
want, err := ioutil.ReadFile(goldenFile)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, string(want), tt.out.String())
|
|
})
|
|
}
|
|
}
|