@@ -848,3 +848,130 @@ func TestAutomation_Sharding(t *testing.T) {
848
848
t .Error (diff )
849
849
}
850
850
}
851
+
852
+ func TestAutomation_GetPrometheusConfig (t * testing.T ) {
853
+ client , mux , teardown := setup ()
854
+ defer teardown ()
855
+
856
+ mux .HandleFunc (fmt .Sprintf ("/api/public/v1.0/groups/%s/automationConfig" , projectID ), func (w http.ResponseWriter , r * http.Request ) {
857
+ testMethod (t , r , http .MethodGet )
858
+ _ , _ = fmt .Fprint (w , `{
859
+ "prometheus" : {
860
+ "enabled": true,
861
+ "listenAddress": "0.0.0.0:9216",
862
+ "metricsPath": "/metrics",
863
+ "mode": "opsManager",
864
+ "passwordHash": "",
865
+ "passwordSalt": "",
866
+ "scheme": "http",
867
+ "tlsPemPassword": "",
868
+ "tlsPemPath": "",
869
+ "username": "user"
870
+ }}` )
871
+ })
872
+
873
+ config , _ , err := client .Automation .GetConfig (ctx , projectID )
874
+ if err != nil {
875
+ t .Fatalf ("Automation.GetConfig returned error: %v" , err )
876
+ }
877
+
878
+ expected := & AutomationConfig {
879
+ Prometheus : & Prometheus {
880
+ Enabled : true ,
881
+ ListenAddress : "0.0.0.0:9216" ,
882
+ MetricsPath : "/metrics" ,
883
+ Mode : "opsManager" ,
884
+ Scheme : "http" ,
885
+ Username : "user" ,
886
+ },
887
+ }
888
+ if diff := deep .Equal (config , expected ); diff != nil {
889
+ t .Error (diff )
890
+ }
891
+ }
892
+
893
+ func TestAutomation_UpdatePrometheusConfig (t * testing.T ) {
894
+ client , mux , teardown := setup ()
895
+ defer teardown ()
896
+
897
+ updateRequest := & AutomationConfig {
898
+ Prometheus : & Prometheus {
899
+ Enabled : true ,
900
+ ListenAddress : "0.0.0.0:9216" ,
901
+ MetricsPath : "/metrics" ,
902
+ Mode : "opsManager" ,
903
+ Scheme : "http" ,
904
+ Username : "user" ,
905
+ TokenFillRateSeconds : 1 ,
906
+ BurstTokenCount : 1 ,
907
+ },
908
+ Auth : Auth {
909
+ AuthoritativeSet : false ,
910
+ AutoAuthMechanism : "MONGODB-CR" ,
911
+ Disabled : true ,
912
+ UsersWanted : []* MongoDBUser {
913
+ {
914
+ Database : "admin" ,
915
+ },
916
+ },
917
+ },
918
+ }
919
+ mux .HandleFunc (fmt .Sprintf ("/api/public/v1.0/groups/%s/automationConfig" , projectID ), func (w http.ResponseWriter , r * http.Request ) {
920
+ expected := map [string ]interface {}{
921
+ "prometheus" : map [string ]interface {}{
922
+ "enabled" : true ,
923
+ "listenAddress" : "0.0.0.0:9216" ,
924
+ "metricsPath" : "/metrics" ,
925
+ "mode" : "opsManager" ,
926
+ "scheme" : "http" ,
927
+ "tlsPemPassword" : "" ,
928
+ "tlsPemPath" : "" ,
929
+ "username" : "user" ,
930
+ "tokenFillRateSeconds" : 1.0 ,
931
+ "burstTokenCount" : 1.0 ,
932
+ },
933
+ "auth" : map [string ]interface {}{
934
+ "authoritativeSet" : false ,
935
+ "autoAuthMechanism" : "MONGODB-CR" ,
936
+ "autoAuthRestrictions" : interface {}(nil ),
937
+ "disabled" : true ,
938
+ "usersDeleted" : interface {}(nil ),
939
+ "usersWanted" : []interface {}{
940
+ map [string ]interface {}{
941
+ "authenticationRestrictions" : interface {}(nil ),
942
+ "db" : "admin" ,
943
+ "roles" : interface {}(nil ),
944
+ "user" : "" ,
945
+ },
946
+ },
947
+ },
948
+ "backupVersions" : interface {}(nil ),
949
+ "balancer" : interface {}(nil ),
950
+ "cpsModules" : interface {}(nil ),
951
+ "indexConfigs" : interface {}(nil ),
952
+ "mongosqlds" : interface {}(nil ),
953
+ "mongots" : interface {}(nil ),
954
+ "onlineArchiveModules" : interface {}(nil ),
955
+ "options" : interface {}(nil ),
956
+ "processes" : interface {}(nil ),
957
+ "replicaSets" : interface {}(nil ),
958
+ "roles" : interface {}(nil ),
959
+ "sharding" : interface {}(nil ),
960
+ }
961
+ var v map [string ]interface {}
962
+ err := json .NewDecoder (r .Body ).Decode (& v )
963
+ if err != nil {
964
+ t .Fatalf ("decode json: %v" , err )
965
+ }
966
+ t .Logf ("v=%#v\n " , v )
967
+ if diff := deep .Equal (v , expected ); diff != nil {
968
+ t .Error (diff )
969
+ }
970
+ _ , _ = fmt .Fprint (w , `{}` )
971
+ })
972
+
973
+ _ , err := client .Automation .UpdateConfig (ctx , projectID , updateRequest )
974
+ if err != nil {
975
+ t .Fatalf ("Automation.UpdateConfig returned error: %v" , err )
976
+ }
977
+ }
0 commit comments