@@ -39,40 +39,49 @@ describe('workflow-helper', () => {
39
39
describe ( 'composePodLogsStreamHandler' , ( ) => {
40
40
it ( 'returns the stream from the default handler if there is no errors.' , async ( ) => {
41
41
const defaultStream = new PassThrough ( ) ;
42
- const defaultHandler = jest . fn ( ( _podName : string , _namespace ?: string ) =>
42
+ const defaultHandler = jest . fn ( ( _podName : string , _createdAt : string , _namespace ?: string ) =>
43
43
Promise . resolve ( defaultStream ) ,
44
44
) ;
45
- const stream = await composePodLogsStreamHandler ( defaultHandler ) ( 'podName' , 'namespace' ) ;
46
- expect ( defaultHandler ) . toBeCalledWith ( 'podName' , 'namespace' ) ;
45
+ const stream = await composePodLogsStreamHandler ( defaultHandler ) (
46
+ 'podName' ,
47
+ '2024-08-13' ,
48
+ 'namespace' ,
49
+ ) ;
50
+ expect ( defaultHandler ) . toBeCalledWith ( 'podName' , '2024-08-13' , 'namespace' ) ;
47
51
expect ( stream ) . toBe ( defaultStream ) ;
48
52
} ) ;
49
53
50
54
it ( 'returns the stream from the fallback handler if there is any error.' , async ( ) => {
51
55
const fallbackStream = new PassThrough ( ) ;
52
- const defaultHandler = jest . fn ( ( _podName : string , _namespace ?: string ) =>
56
+ const defaultHandler = jest . fn ( ( _podName : string , _createdAt : string , _namespace ?: string ) =>
53
57
Promise . reject ( 'unknown error' ) ,
54
58
) ;
55
- const fallbackHandler = jest . fn ( ( _podName : string , _namespace ?: string ) =>
59
+ const fallbackHandler = jest . fn ( ( _podName : string , _createdAt : string , _namespace ?: string ) =>
56
60
Promise . resolve ( fallbackStream ) ,
57
61
) ;
58
62
const stream = await composePodLogsStreamHandler ( defaultHandler , fallbackHandler ) (
59
63
'podName' ,
64
+ '2024-08-13' ,
60
65
'namespace' ,
61
66
) ;
62
- expect ( defaultHandler ) . toBeCalledWith ( 'podName' , 'namespace' ) ;
63
- expect ( fallbackHandler ) . toBeCalledWith ( 'podName' , 'namespace' ) ;
67
+ expect ( defaultHandler ) . toBeCalledWith ( 'podName' , '2024-08-13' , ' namespace') ;
68
+ expect ( fallbackHandler ) . toBeCalledWith ( 'podName' , '2024-08-13' , ' namespace') ;
64
69
expect ( stream ) . toBe ( fallbackStream ) ;
65
70
} ) ;
66
71
67
72
it ( 'throws error if both handler and fallback fails.' , async ( ) => {
68
- const defaultHandler = jest . fn ( ( _podName : string , _namespace ?: string ) =>
73
+ const defaultHandler = jest . fn ( ( _podName : string , _createdAt : string , _namespace ?: string ) =>
69
74
Promise . reject ( 'unknown error for default' ) ,
70
75
) ;
71
- const fallbackHandler = jest . fn ( ( _podName : string , _namespace ?: string ) =>
76
+ const fallbackHandler = jest . fn ( ( _podName : string , _createdAt : string , _namespace ?: string ) =>
72
77
Promise . reject ( 'unknown error for fallback' ) ,
73
78
) ;
74
79
await expect (
75
- composePodLogsStreamHandler ( defaultHandler , fallbackHandler ) ( 'podName' , 'namespace' ) ,
80
+ composePodLogsStreamHandler ( defaultHandler , fallbackHandler ) (
81
+ 'podName' ,
82
+ '2024-08-13' ,
83
+ 'namespace' ,
84
+ ) ,
76
85
) . rejects . toEqual ( 'unknown error for fallback' ) ;
77
86
} ) ;
78
87
} ) ;
@@ -82,7 +91,7 @@ describe('workflow-helper', () => {
82
91
const mockedGetPodLogs : jest . Mock = getPodLogs as any ;
83
92
mockedGetPodLogs . mockResolvedValueOnce ( 'pod logs' ) ;
84
93
85
- const stream = await getPodLogsStreamFromK8s ( 'podName' , 'namespace' ) ;
94
+ const stream = await getPodLogsStreamFromK8s ( 'podName' , '' , ' namespace') ;
86
95
expect ( mockedGetPodLogs ) . toBeCalledWith ( 'podName' , 'namespace' , 'main' ) ;
87
96
expect ( stream . read ( ) . toString ( ) ) . toBe ( 'pod logs' ) ;
88
97
} ) ;
@@ -101,24 +110,34 @@ describe('workflow-helper', () => {
101
110
client,
102
111
key : 'folder/key' ,
103
112
} ;
104
- const createRequest = jest . fn ( ( _podName : string , _namespace ?: string ) =>
113
+ const createRequest = jest . fn ( ( _podName : string , _createdAt : string , _namespace ?: string ) =>
105
114
Promise . resolve ( configs ) ,
106
115
) ;
107
- const stream = await toGetPodLogsStream ( createRequest ) ( 'podName' , 'namespace' ) ;
116
+ const stream = await toGetPodLogsStream ( createRequest ) ( 'podName' , '2024-08-13' , ' namespace') ;
108
117
expect ( mockedClientGetObject ) . toBeCalledWith ( 'bucket' , 'folder/key' ) ;
109
118
} ) ;
110
119
} ) ;
111
120
112
121
describe ( 'createPodLogsMinioRequestConfig' , ( ) => {
113
122
it ( 'returns a MinioRequestConfig factory with the provided minioClientOptions, bucket, and prefix.' , async ( ) => {
114
123
const mockedClient : jest . Mock = MinioClient as any ;
115
- const requestFunc = await createPodLogsMinioRequestConfig ( minioConfig , 'bucket' , 'prefix' ) ;
116
- const request = await requestFunc ( 'workflow-name-abc' , 'namespace' ) ;
124
+ const requestFunc = await createPodLogsMinioRequestConfig (
125
+ minioConfig ,
126
+ 'bucket' ,
127
+ 'artifacts/{{workflow.name}}/{{workflow.creationTimestamp.Y}}/{{workflow.creationTimestamp.m}}/{{workflow.creationTimestamp.d}}/{{pod.name}}' ,
128
+ ) ;
129
+ const request = await requestFunc (
130
+ 'workflow-name-system-container-impl-foo' ,
131
+ '2024-08-13' ,
132
+ 'namespace' ,
133
+ ) ;
117
134
118
135
expect ( mockedClient ) . toBeCalledWith ( minioConfig ) ;
119
136
expect ( request . client ) . toBeInstanceOf ( MinioClient ) ;
120
137
expect ( request . bucket ) . toBe ( 'bucket' ) ;
121
- expect ( request . key ) . toBe ( 'prefix/workflow-name/workflow-name-abc/main.log' ) ;
138
+ expect ( request . key ) . toBe (
139
+ 'artifacts/workflow-name/2024/08/13/workflow-name-system-container-impl-foo/main.log' ,
140
+ ) ;
122
141
} ) ;
123
142
} ) ;
124
143
@@ -174,7 +193,7 @@ describe('workflow-helper', () => {
174
193
mockedClientGetObject . mockResolvedValueOnce ( objStream ) ;
175
194
objStream . end ( 'some fake logs.' ) ;
176
195
177
- const stream = await getPodLogsStreamFromWorkflow ( 'workflow-name-abc' , " 2024-07-09" ) ;
196
+ const stream = await getPodLogsStreamFromWorkflow ( 'workflow-name-abc' , ' 2024-07-09' ) ;
178
197
179
198
expect ( mockedGetArgoWorkflow ) . toBeCalledWith ( 'workflow-name' ) ;
180
199
0 commit comments