Skip to content

Commit

Permalink
remove duplication
Browse files Browse the repository at this point in the history
Signed-off-by: Benny Zlotnik <[email protected]>
  • Loading branch information
bennyz committed Dec 19, 2023
1 parent 0c8f80d commit 7a96fc8
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions cmd/openstack-populator/openstack-populator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func setupMockServer() (*httptest.Server, string, int, error) {
mux := http.NewServeMux()

port := listener.Addr().(*net.TCPAddr).Port
identityServerURL := fmt.Sprintf("http://localhost:%d", port)
baseURL := fmt.Sprintf("http://localhost:%d", port)

mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
Expand All @@ -36,7 +36,7 @@ func setupMockServer() (*httptest.Server, string, int, error) {
}
]
}
}`, identityServerURL)
}`, baseURL)
fmt.Fprint(w, response)
})

Expand All @@ -48,11 +48,9 @@ func setupMockServer() (*httptest.Server, string, int, error) {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("X-Subject-Token", "MIIFvgY")
w.WriteHeader(http.StatusCreated)
identityPublicURL := fmt.Sprintf("http://localhost:%d/v3/", port)
identityAdminURL := fmt.Sprintf("http://localhost:%d/v3/", port)
identityInternalURL := fmt.Sprintf("http://localhost:%d/v3/", port)
imageServiceURL := fmt.Sprintf("http://localhost:%d/v2/images", port)

identityServer := fmt.Sprintf("%s/v3/", baseURL)
imageServiceURL := fmt.Sprintf("%s/v2/images", baseURL)
fmt.Println("identityServer ", identityServer)
response := fmt.Sprintf(`{
"token": {
"methods": ["password"],
Expand Down Expand Up @@ -113,9 +111,9 @@ func setupMockServer() (*httptest.Server, string, int, error) {
"issued_at": "201406-10T20:55:16.806027Z"
}
}`,
identityPublicURL,
identityAdminURL,
identityInternalURL,
identityServer,
identityServer,
identityServer,
imageServiceURL)

fmt.Fprint(w, response)
Expand All @@ -126,7 +124,7 @@ func setupMockServer() (*httptest.Server, string, int, error) {

server.Start()

return server, identityServerURL, port, nil
return server, baseURL, port, nil
}

func TestPopulate(t *testing.T) {
Expand Down Expand Up @@ -165,7 +163,7 @@ func TestPopulate(t *testing.T) {
t.Fatalf("Failed to read file: %v", err)
}

if string(content) != "mock_data\n" {
if string(content) != "m2ock_data\n" {
t.Errorf("Expected %s, got %s", "mock_data\n", string(content))
}

Expand Down

0 comments on commit 7a96fc8

Please sign in to comment.