Skip to content

Commit a46a2c3

Browse files
committed
feat: add copilot instruction
Signed-off-by: Jack Yu <[email protected]>
1 parent ac32dd6 commit a46a2c3

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
applyTo: '**'
3+
---
4+
5+
## Must Do
6+
7+
- When writing integrations tests, please refer to the existing tests in `tests/harvester_e2e_tests/integrations` directory.
8+
- When writing api tests, please refer to the existing tests in `tests/harvester_e2e_tests/apis` directory.
9+
- When mentioning `shared in the class` or `sharing in the class` , the `@pytest.fixture` should be `class`. Then, use `yield` generator to create the shared fixture.
10+
- Test cases should have one passed case and one failed case at least.
11+
- All comments are written in English, please do not use other languages.
12+
13+
14+
### Do with API
15+
16+
- When adding a new Harvester API, if the resource doesn't eixst under `apiclient/harvester_api/managers`, please create a new file under that directory with Plural form. Then, load it in `apiclient/harvester_api/api.py` and add it to the `apiclient/harvester_api/managers/__init__.py` class.
17+
- Refer to `apiclient/harvester_api/managers/images.py` for how to implement a new API manager
18+
- Follow these status codes to assert the Harvester API result:
19+
- `201` for successfully created when creating
20+
- `200` for success for others
21+
22+
## Don't do
23+
24+
- Do not use underscore `_` prefix method in test case, like `api_client.[resource]._[method]`
25+
- Do not write function in the function, like this:
26+
```python
27+
def outer_function(self):
28+
def inner_function():
29+
# do something
30+
inner_function()
31+
```
32+
- Do not import library in the function, like this:
33+
```python
34+
def function(self):
35+
import some_library
36+
# do something
37+
```
38+
39+
## Harvester e2e Integration Test Template
40+
41+
When writing a new Harvester e2e integration test, please use the following templates:
42+
43+
```python
44+
## some shared fixtures
45+
@pytest.fixture(scope="module or class")
46+
def shared_fixture():
47+
"""
48+
Comments
49+
"""
50+
# 1. Prepare the environment and data
51+
# 2. call API, sss is resource, xxx is the method
52+
code, data = api_client.sss.xxx()
53+
# 3. Assert the result with code (status code)
54+
assert code == xxxx, f"Expected status code xxxx, got {code} with data: {data}"
55+
output = {
56+
"key1": "value1",
57+
"key2": "value2",
58+
}
59+
yield output
60+
# 4. Teardown if needed
61+
api_client.sss.teardown_method()
62+
63+
@pytest.mark.p0
64+
@pytest.mark.skip_version_if("???", reason="???")
65+
class TestXXXX:
66+
"""
67+
Comments
68+
"""
69+
70+
@pytest.mark.p0
71+
def test_XXXX(self, ${some fixtures and shared_fixture}):
72+
"""
73+
Comments
74+
"""
75+
# 1. Prepare the environment and data
76+
shared_data = shared_fixture
77+
# 2. call API, sss is resource, xxx is the method
78+
code, data = api_client.sss.xxx()
79+
# 3. Assert the result with code (status code)
80+
assert code == xxxx, f"Expected status code xxxx, got {code} with data: {data}"
81+
```
82+
83+
### Harvester API Template
84+
85+
When writing a new Harvester API, please use the following template:
86+
87+
```python
88+
import base64
89+
from .base import BaseManager, DEFAULT_NAMESPACE
90+
91+
92+
class xxxtManager(BaseManager):
93+
PATH_fmt = "/api/v1/namespaces/{ns}/xxxx/{name}"
94+
CREATE_fmt = "v1/harvester/xxxx"
95+
96+
def create_data(self, name, namespace, data, annotations=None):
97+
return {
98+
"type": "xxxxx",
99+
"metadata": {
100+
"namespace": namespace,
101+
"name": name,
102+
"annotations": annotations
103+
},
104+
}
105+
106+
def create(self, name, data, namespace=DEFAULT_NAMESPACE, annotations=None, **kwargs):
107+
data = self.create_data(name, namespace, data, annotations=annotations)
108+
return self._create(
109+
self.CREATE_fmt,
110+
json=data, **kwargs)
111+
112+
def get(self, name, namespace=DEFAULT_NAMESPACE, *, raw=False):
113+
return self._get(
114+
self.PATH_fmt.format(ns=namespace, name=name), raw=raw)
115+
116+
def delete(self, name, namespace=DEFAULT_NAMESPACE, *, raw=False):
117+
return self._delete(
118+
self.PATH_fmt.format(ns=namespace, name=name), raw=raw)
119+
120+
```

0 commit comments

Comments
 (0)