MCPcopy Index your code
hub / github.com/coder/coder / TestGetPresetsAtFailureLimit

Function TestGetPresetsAtFailureLimit

coderd/database/querier_test.go:6937–7237  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6935}
6936
6937func TestGetPresetsAtFailureLimit(t *testing.T) {
6938 t.Parallel()
6939
6940 now := dbtime.Now()
6941 hourBefore := now.Add(-time.Hour)
6942 orgID := uuid.New()
6943 userID := uuid.New()
6944
6945 findPresetByTmplVersionID := func(hardLimitedPresets []database.GetPresetsAtFailureLimitRow, tmplVersionID uuid.UUID) *database.GetPresetsAtFailureLimitRow {
6946 for _, preset := range hardLimitedPresets {
6947 if preset.TemplateVersionID == tmplVersionID {
6948 return &preset
6949 }
6950 }
6951
6952 return nil
6953 }
6954
6955 testCases := []struct {
6956 name string
6957 // true - build is successful
6958 // false - build is unsuccessful
6959 buildSuccesses []bool
6960 hardLimit int64
6961 expHitHardLimit bool
6962 }{
6963 {
6964 name: "failed build",
6965 buildSuccesses: []bool{false},
6966 hardLimit: 1,
6967 expHitHardLimit: true,
6968 },
6969 {
6970 name: "2 failed builds",
6971 buildSuccesses: []bool{false, false},
6972 hardLimit: 1,
6973 expHitHardLimit: true,
6974 },
6975 {
6976 name: "successful build",
6977 buildSuccesses: []bool{true},
6978 hardLimit: 1,
6979 expHitHardLimit: false,
6980 },
6981 {
6982 name: "last build is failed",
6983 buildSuccesses: []bool{true, true, false},
6984 hardLimit: 1,
6985 expHitHardLimit: true,
6986 },
6987 {
6988 name: "last build is successful",
6989 buildSuccesses: []bool{false, false, true},
6990 hardLimit: 1,
6991 expHitHardLimit: false,
6992 },
6993 {
6994 name: "last 3 builds are failed - hard limit is reached",

Callers

nothing calls this directly

Calls 15

NowFunction · 0.92
NewDBFunction · 0.92
ContextFunction · 0.92
OrganizationFunction · 0.92
UserFunction · 0.92
createPrebuiltWorkspaceFunction · 0.85
DurationMethod · 0.80
createTemplateFunction · 0.70
AddMethod · 0.65
NewMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected