MCPcopy Index your code
hub / github.com/dnote/dnote / TestInit_APIEndpoint

Function TestInit_APIEndpoint

pkg/cli/infra/init_test.go:94–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

92}
93
94func TestInit_APIEndpoint(t *testing.T) {
95 // Create a temporary directory for test
96 tmpDir, err := os.MkdirTemp("", "dnote-init-test-*")
97 if err != nil {
98 t.Fatal(errors.Wrap(err, "creating temp dir"))
99 }
100 defer os.RemoveAll(tmpDir)
101
102 // Set up environment to use our temp directory
103 t.Setenv("XDG_CONFIG_HOME", fmt.Sprintf("%s/config", tmpDir))
104 t.Setenv("XDG_DATA_HOME", fmt.Sprintf("%s/data", tmpDir))
105 t.Setenv("XDG_CACHE_HOME", fmt.Sprintf("%s/cache", tmpDir))
106
107 // Force dirs package to reload with new environment
108 dirs.Reload()
109
110 // Initialize - should create config with default apiEndpoint
111 ctx, err := Init("test-version", "", "")
112 if err != nil {
113 t.Fatal(errors.Wrap(err, "initializing"))
114 }
115 defer ctx.DB.Close()
116
117 // Read the config that was created
118 cf, err := config.Read(*ctx)
119 if err != nil {
120 t.Fatal(errors.Wrap(err, "reading config"))
121 }
122
123 // Context should use the apiEndpoint from config
124 assert.Equal(t, ctx.APIEndpoint, DefaultAPIEndpoint, "context should use apiEndpoint from config")
125 assert.Equal(t, cf.APIEndpoint, DefaultAPIEndpoint, "context should use apiEndpoint from config")
126}

Callers

nothing calls this directly

Calls 5

ReloadFunction · 0.92
ReadFunction · 0.92
EqualFunction · 0.92
InitFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected