package gql_test import ( "context" "testing" "git.kapelle.org/niklas/s3browser/internal/gql" "git.kapelle.org/niklas/s3browser/internal/loader" "git.kapelle.org/niklas/s3browser/internal/s3" "github.com/graph-gophers/dataloader" "github.com/graphql-go/graphql" "github.com/stretchr/testify/assert" ) func setup(t *testing.T) (*assert.Assertions, context.Context, graphql.Schema) { assert := assert.New(t) ctx := context.Background() schema, _ := gql.GraphqlSchema() s3, err := s3.NewMockS3([]string{"bucket1"}) assert.NoError(err) ctx = context.WithValue(ctx, "s3Client", s3) loader := loader.NewLoader(loader.CacheConfig{ ListObjectsLoaderCache: &dataloader.NoCache{}, ListObjectsRecursiveLoaderCache: &dataloader.NoCache{}, StatObjectLoaderCache: &dataloader.NoCache{}, ListBucketsLoaderCache: &dataloader.NoCache{}, }) assert.NotNil(loader) ctx = context.WithValue(ctx, "loader", loader) return assert, ctx, schema } func do(ctx context.Context, schema graphql.Schema, query string) *graphql.Result { params := graphql.Params{ Schema: schema, RequestString: query, Context: ctx, } r := graphql.Do(params) return r } func TestCreateSchema(t *testing.T) { assert := assert.New(t) assert.NotPanics(func() { gql.GraphqlTypes() }) var schema graphql.Schema var err error assert.NotPanics(func() { schema, err = gql.GraphqlSchema() }) assert.NoError(err) assert.NotNil(schema) } func TestAuth(t *testing.T) { assert, ctx, schema := setup(t) r := do(ctx, schema, ` { authorized } `) t.Logf("Data: %v", r.Data) assert.Len(r.Errors, 0) }