|
1 | 1 | import test from "ava"; |
2 | 2 | import sinon from "sinon"; |
3 | 3 |
|
| 4 | +import { Feature } from "../feature-flags"; |
4 | 5 | import { RepositoryPropertyName } from "../feature-flags/properties"; |
5 | | -import { |
6 | | - getTestActionsEnv, |
7 | | - RecordingLogger, |
8 | | - setupTests, |
9 | | -} from "../testing-utils"; |
| 6 | +import { callee, setupTests } from "../testing-utils"; |
10 | 7 |
|
11 | 8 | import { getConfigFileInput } from "./file"; |
12 | 9 |
|
13 | 10 | setupTests(test); |
14 | 11 |
|
15 | 12 | test("getConfigFileInput returns undefined by default", async (t) => { |
16 | | - const logger = new RecordingLogger(); |
17 | | - const actionsEnv = getTestActionsEnv(); |
18 | | - const result = getConfigFileInput(logger, actionsEnv, {}, true); |
19 | | - t.is(result, undefined); |
| 13 | + await callee(getConfigFileInput) |
| 14 | + .withArgs({}) |
| 15 | + .withFeatures([Feature.ConfigFileRepositoryProperty]) |
| 16 | + .passes(async (fn) => t.is(await fn(), undefined)); |
20 | 17 | }); |
21 | 18 |
|
22 | 19 | const repositoryProperties = { |
23 | 20 | [RepositoryPropertyName.CONFIG_FILE]: "/path/from/property", |
24 | 21 | }; |
25 | 22 |
|
26 | 23 | test("getConfigFileInput returns input value", async (t) => { |
27 | | - const logger = new RecordingLogger(); |
28 | | - const actionsEnv = getTestActionsEnv(); |
29 | 24 | const testInput = "/some/path"; |
| 25 | + const target = callee(getConfigFileInput).withFeatures([ |
| 26 | + Feature.ConfigFileRepositoryProperty, |
| 27 | + ]); |
| 28 | + |
| 29 | + const actionsEnv = target.getState().actions; |
30 | 30 | sinon |
31 | 31 | .stub(actionsEnv, "getOptionalInput") |
32 | 32 | .withArgs("config-file") |
33 | 33 | .returns(testInput); |
34 | 34 |
|
35 | 35 | // Even though both an input and repository property are configured, |
36 | 36 | // we prefer the direct input to the Action. |
37 | | - const result = getConfigFileInput( |
38 | | - logger, |
39 | | - actionsEnv, |
40 | | - repositoryProperties, |
41 | | - true, |
42 | | - ); |
43 | | - t.is(result, testInput); |
| 37 | + const targetWithArgs = target |
| 38 | + .withActions(actionsEnv) |
| 39 | + .withArgs(repositoryProperties); |
| 40 | + await targetWithArgs.passes(async (fn) => t.is(await fn(), testInput)); |
44 | 41 |
|
45 | 42 | // Check for the expected log message. |
46 | | - t.true(logger.hasMessage("Using configuration file input from workflow")); |
| 43 | + t.true( |
| 44 | + targetWithArgs |
| 45 | + .getLogger() |
| 46 | + .hasMessage("Using configuration file input from workflow"), |
| 47 | + ); |
47 | 48 | }); |
48 | 49 |
|
49 | 50 | test("getConfigFileInput returns repository property value", async (t) => { |
50 | | - const logger = new RecordingLogger(); |
51 | | - const actionsEnv = getTestActionsEnv(); |
52 | | - |
53 | 51 | // Since there is no direct input, we should use the repository property. |
54 | | - const result = getConfigFileInput( |
55 | | - logger, |
56 | | - actionsEnv, |
57 | | - repositoryProperties, |
58 | | - true, |
| 52 | + const target = callee(getConfigFileInput) |
| 53 | + .withFeatures([Feature.ConfigFileRepositoryProperty]) |
| 54 | + .withArgs(repositoryProperties); |
| 55 | + |
| 56 | + await target.passes(async (fn) => |
| 57 | + t.is(await fn(), repositoryProperties[RepositoryPropertyName.CONFIG_FILE]), |
59 | 58 | ); |
60 | | - t.is(result, repositoryProperties[RepositoryPropertyName.CONFIG_FILE]); |
61 | 59 |
|
62 | 60 | // Check for the expected log message. |
63 | 61 | t.true( |
64 | | - logger.hasMessage( |
65 | | - "Using configuration file input from repository property", |
66 | | - ), |
| 62 | + target |
| 63 | + .getLogger() |
| 64 | + .hasMessage("Using configuration file input from repository property"), |
67 | 65 | ); |
68 | 66 | }); |
69 | 67 |
|
70 | 68 | test("getConfigFileInput ignores empty repository property value", async (t) => { |
71 | | - const logger = new RecordingLogger(); |
72 | | - const actionsEnv = getTestActionsEnv(); |
73 | | - |
74 | 69 | // Since the repository property value is an empty/whitespace string, we should ignore it. |
75 | | - const result = getConfigFileInput( |
76 | | - logger, |
77 | | - actionsEnv, |
78 | | - { |
79 | | - [RepositoryPropertyName.CONFIG_FILE]: " ", |
80 | | - }, |
81 | | - true, |
82 | | - ); |
83 | | - t.is(result, undefined); |
| 70 | + await callee(getConfigFileInput) |
| 71 | + .withFeatures([Feature.ConfigFileRepositoryProperty]) |
| 72 | + .withArgs({ [RepositoryPropertyName.CONFIG_FILE]: " " }) |
| 73 | + .passes(async (fn) => t.is(await fn(), undefined)); |
84 | 74 | }); |
85 | 75 |
|
86 | 76 | test("getConfigFileInput ignores repository property value when FF is off", async (t) => { |
87 | | - const logger = new RecordingLogger(); |
88 | | - const actionsEnv = getTestActionsEnv(); |
89 | | - |
90 | 77 | // Since the FF is off, we should ignore the repository property value. |
91 | | - const result = getConfigFileInput( |
92 | | - logger, |
93 | | - actionsEnv, |
94 | | - repositoryProperties, |
95 | | - false, |
96 | | - ); |
97 | | - t.is(result, undefined); |
| 78 | + const target = callee(getConfigFileInput) |
| 79 | + .withFeatures([]) |
| 80 | + .withArgs(repositoryProperties); |
| 81 | + |
| 82 | + await target.passes(async (fn) => t.is(await fn(), undefined)); |
98 | 83 |
|
99 | 84 | t.false( |
100 | | - logger.hasMessage( |
101 | | - "Using configuration file input from repository property", |
102 | | - ), |
| 85 | + target |
| 86 | + .getLogger() |
| 87 | + .hasMessage("Using configuration file input from repository property"), |
103 | 88 | ); |
104 | 89 | t.true( |
105 | | - logger.hasMessage( |
106 | | - "Ignoring configuration file input from repository property, because the corresponding feature flag is disabled.", |
107 | | - ), |
| 90 | + target |
| 91 | + .getLogger() |
| 92 | + .hasMessage( |
| 93 | + "Ignoring configuration file input from repository property, because the corresponding feature flag is disabled.", |
| 94 | + ), |
108 | 95 | ); |
109 | 96 | }); |
0 commit comments