Skip to content

fix: hide typeInfo in KubeResourceInfo but allow access to apiGroup, kind #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ private void setTypeInfo(KubernetesTypeInfo typeInfo) {
this.typeInfo = typeInfo;
}

public String getApiGroup() {
if (typeInfo == null) {
return null;
}
return typeInfo.getApiGroup();
}

public String getKind() {
if (typeInfo == null) {
return null;
}
return typeInfo.getKind();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class KubernetesResourceInfoTest {
Expand Down Expand Up @@ -297,6 +298,54 @@ public void create_returns_empty_info_for_unsupported_file_type() {
assertThat(resourceInfo.getNamespace()).isNull();
}

@Test
public void getApiGroup_returns_apiGroup_of_typeInfo() {
// given
KubernetesResourceInfo info = new KubernetesResourceInfo("obiwan", "stewjon", typeInfo);

// when
info.getApiGroup();

// then
verify(typeInfo).getApiGroup();
}

@Test
public void getApiGroup_returns_null_given_typeInfo_is_null() {
// given
KubernetesResourceInfo info = new KubernetesResourceInfo("obiwan", "tatooine", null);

// when
String apiGroup = info.getApiGroup();

// then
assertThat(apiGroup).isNull();
}

@Test
public void getKind_returns_kind_of_typeInfo() {
// given
KubernetesResourceInfo info = new KubernetesResourceInfo("luke", "stewjon", typeInfo);

// when
info.getKind();

// then
verify(typeInfo).getKind();
}

@Test
public void getKind_returns_null_given_typeInfo_is_nul() {
// given
KubernetesResourceInfo info = new KubernetesResourceInfo("luke", "stewjon", null);

// when
String kind = info.getKind();

// then
assertThat(kind).isNull();
}

private void mockCreateKubernetesTypeInfo(KubernetesTypeInfo typeInfo, PsiFile file) {
mockStatic.when(() -> KubernetesTypeInfo.create(file))
.thenReturn(typeInfo);
Expand Down
Loading