-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address duplicate node-id issue with math/rand (#127)
* Addresses duplicate node-id issue with math/rand * Remove extra newline * Add tests * Throw error if we are unable to resolve the node id from the config file * Cleanup * Cleaning up test
- Loading branch information
Showing
4 changed files
with
134 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package flypg | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
const ( | ||
repmgrTestDirectory = "./test_results" | ||
repmgrConfigFilePath = "./test_results/repmgr.conf" | ||
repgmrInternalConfigFilePath = "./test_results/repmgr.internal.conf" | ||
repgmrUserConfigFilePath = "./test_results/repmgr.internal.conf" | ||
) | ||
|
||
func TestRepmgrConfigDefaults(t *testing.T) { | ||
if err := setup(t); err != nil { | ||
t.Fatal(err) | ||
} | ||
defer cleanup() | ||
|
||
conf := &RepMgr{ | ||
AppName: "test-app", | ||
PrimaryRegion: "dev", | ||
Region: "dev", | ||
ConfigPath: repmgrConfigFilePath, | ||
InternalConfigPath: repgmrInternalConfigFilePath, | ||
UserConfigPath: repgmrUserConfigFilePath, | ||
DataDir: repmgrTestDirectory, | ||
PrivateIP: "127.0.0.1", | ||
Port: 5433, | ||
DatabaseName: "repmgr", | ||
} | ||
|
||
if err := conf.setDefaults(); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if conf.internalConfig["node_name"] != "'127.0.0.1'" { | ||
t.Fatalf("expected node_name to be '127.0.0.1', got %v", conf.internalConfig["node_name"]) | ||
} | ||
|
||
if conf.internalConfig["node_id"] == "" { | ||
t.Fatalf("expected node_id to not be empty, got %q", conf.internalConfig["node_id"]) | ||
} | ||
|
||
} | ||
|
||
func TestRepmgrNodeIDGeneration(t *testing.T) { | ||
if err := setup(t); err != nil { | ||
t.Fatal(err) | ||
} | ||
defer cleanup() | ||
|
||
conf := &RepMgr{ | ||
AppName: "test-app", | ||
PrimaryRegion: "dev", | ||
Region: "dev", | ||
ConfigPath: repmgrConfigFilePath, | ||
InternalConfigPath: repgmrInternalConfigFilePath, | ||
UserConfigPath: repgmrUserConfigFilePath, | ||
DataDir: repmgrTestDirectory, | ||
PrivateIP: "127.0.0.1", | ||
Port: 5433, | ||
DatabaseName: "repmgr", | ||
} | ||
|
||
if err := conf.setDefaults(); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if err := writeInternalConfigFile(conf); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
nodeID := conf.internalConfig["node_id"] | ||
|
||
resolvedNodeID, err := conf.resolveNodeID() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if nodeID != resolvedNodeID { | ||
t.Fatalf("expected node_id to be %s, got %q", nodeID, resolvedNodeID) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters