MCPcopy Create free account
hub / github.com/cli/cli / TestSchemaSourceLocate

Function TestSchemaSourceLocate

script/ghmock/schemafiles_test.go:58–161  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func TestSchemaSourceLocate(t *testing.T) {
59 schema := readTestdata(t, "schema.graphql")
60 const oldCopy = "type Query { old: String }"
61
62 tests := []struct {
63 name string
64 env string
65 cached string
66 served map[string]string
67 wantPath string
68 wantContent string
69 wantProgress string
70 wantErr string
71 }{
72 {
73 name: "the environment variable wins",
74 env: "<testdata>/schema.graphql",
75 cached: oldCopy,
76 wantPath: "<testdata>/schema.graphql",
77 wantContent: schema,
78 },
79 {
80 name: "a missing file in the environment variable is an error",
81 env: "<testdata>/nope.graphql",
82 wantErr: "GHMOCK_GRAPHQL_SCHEMA: stat <testdata>/nope.graphql: no such file or directory",
83 },
84 {
85 name: "a folder in the environment variable is an error",
86 env: "<testdata>",
87 wantErr: "GHMOCK_GRAPHQL_SCHEMA: <testdata> is a directory",
88 },
89 {
90 name: "a cached copy is used",
91 cached: oldCopy,
92 wantPath: "<cache>/schema.docs.graphql",
93 wantContent: oldCopy,
94 },
95 {
96 name: "a missing copy is downloaded",
97 served: map[string]string{"/schema.graphql": schema},
98 wantPath: "<cache>/schema.docs.graphql",
99 wantContent: schema,
100 wantProgress: "ghmock: downloading GitHub's GraphQL schema to <cache>/schema.docs.graphql\n",
101 },
102 {
103 name: "a failed download",
104 served: map[string]string{},
105 wantProgress: "ghmock: downloading GitHub's GraphQL schema to <cache>/schema.docs.graphql\n",
106 wantErr: "downloading GitHub's GraphQL schema from <server>/schema.graphql: HTTP 404 (without network access, set GHMOCK_GRAPHQL_SCHEMA to a local copy)",
107 },
108 {
109 name: "a download that isn't a schema",
110 served: map[string]string{"/schema.graphql": "<html>"},
111 wantProgress: "ghmock: downloading GitHub's GraphQL schema to <cache>/schema.docs.graphql\n",
112 wantErr: "downloading GitHub's GraphQL schema from <server>/schema.graphql: not a usable GraphQL schema: line 1, column 1: Unexpected <Invalid> (without network access, set GHMOCK_GRAPHQL_SCHEMA to a local copy)",
113 },
114 {
115 name: "an empty download",

Callers

nothing calls this directly

Calls 14

readTestdataFunction · 0.85
useCacheDirFunction · 0.85
serveSchemasFunction · 0.85
MkdirAllMethod · 0.80
WriteFileMethod · 0.80
JoinMethod · 0.80
locateMethod · 0.80
EqualMethod · 0.80
ReplaceMethod · 0.80
EmptyMethod · 0.80
ModeMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected